package com.swm.model;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import com.sun.jersey.spi.resource.Singleton;
import com.swm.service.MemberService;


@Singleton
public class DataManager {
	
	private static DataManager dataMrg = null;
	
	public static DataManager getInstance(){
		if ( dataMrg == null ){
			dataMrg = new DataManager();
			return dataMrg;
		}
		return dataMrg;		
	}
	
	List<Project> projectList = new ArrayList<Project>();
	List<User> totalUserList  = new ArrayList<User>();

	public List<User> getUserList() {
		return totalUserList;
	}
	public List<Project> getProjects() {
		return projectList;
	}

	public void setUserList(List<User> totalUserList) {
		this.totalUserList = totalUserList;
	}
	
	public User getUser( String userID ){
		for( User user : totalUserList ){
			if ( user.isEqual( userID ))
				return user;
		}
		return null;
	}
	
	public boolean addUser( User user ){
		return totalUserList.add( user );
	}
	
	public boolean addProject( Project project ){
		return projectList.add( project );
	}	
	
	public boolean addTestcase( Project project, Testcase testcase  ){
		return project.addTestcase( testcase );
	}
	
	public Project getProject( String projectID ){
		for( Project project : projectList ){
			if ( project.isEqual( projectID ))
				return project;
		}
		return null;
	}
	
	public boolean deleteTestcase( Project project, Testcase testcase) {	
		return project.delTestcase(testcase);
	}
	public boolean modifyTestcase( Project project, Testcase testcase ) {
		// TODO Auto-generated method stub
		return project.modifyTestcase(testcase);
	}
	
	
}
